package top.drinyeit.weilong.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import top.drinyeit.weilong.R;
import top.drinyeit.weilong.adapter.StoreAdapter;
import top.drinyeit.weilong.base.BaseActivity;
import top.drinyeit.weilong.fragment.StoreAllFragment;
import top.drinyeit.weilong.fragment.StoreHomeFragment;
import top.drinyeit.weilong.fragment.StoreNewFragment;
import top.drinyeit.weilong.presenter.StorePresenter;

/**
 * Created by bigHead on 2017/11/17.
 */

public class StoreActivity extends BaseActivity {

    int position = 0;
    private RelativeLayout shop_search;
    public ImageView fenlei,shopImg;
    private LinearLayout shop_back,store;
    private TabLayout mTabLayout;
    private ViewPager shop_ViewPager;
    private StoreAdapter storeAdapter;
    private List<Fragment> list;
    private List<String> mNameList;
    public TextView store_name;
    public TextView search_tx;
    private StorePresenter storePresenter;

    private LinearLayout shop_front;
    private LinearLayout all_good;

    private int storeId;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_store);

        initView();
        initIntent();
        initData();
        initListener();
        setTitle();
    }

    private void initView() {
        shop_search = (RelativeLayout) findViewById(R.id.shop_search);
        fenlei = (ImageView) findViewById(R.id.fenlei);
        shop_back = (LinearLayout) findViewById(R.id.shop_back);
        mTabLayout = findViewById(R.id.mTabLayout);
        shop_ViewPager = (ViewPager) findViewById(R.id.shop_ViewPager);
        store_name = findViewById(R.id.store_name);
        store = findViewById(R.id.store);
        shopImg = findViewById(R.id.iv_shop_img);
        search_tx = findViewById(R.id.search_tx);
        initViewPager();
    }

    private void initIntent() {
        Bundle bundle = getIntent().getExtras();
        storeId = bundle.getInt("store_id");
    }

    private void initData(){
        storePresenter = new StorePresenter(this);
        Map<String,Object> map = new HashMap<>();
        map.put("action","commodity_store_info");
        map.put("store_id",storeId);
        storePresenter.getStoreInfo(map);
    }

    public void initListener() {
        shop_search.setVisibility(View.VISIBLE);

        shop_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        store.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(StoreActivity.this,StoreInfoActivity.class);
                intent.putExtra("store_id",storeId);
                startActivity(intent);
            }
        });

        search_tx.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(StoreActivity.this,ShopSearchActivity.class);
                intent.putExtra("store_id",storeId);
                startActivity(intent);
            }
        });

    }

    public void initViewPager() {
        list = new ArrayList<>();
        mNameList = new ArrayList<>();
        mNameList.add("店铺首页");
        mNameList.add("全部宝贝");
        mNameList.add("新品上架");
        list.add(new StoreHomeFragment());
        list.add(new StoreAllFragment());
        list.add(new StoreNewFragment());
        storeAdapter = new StoreAdapter(getSupportFragmentManager(), list, mNameList);
        shop_ViewPager.setAdapter(storeAdapter);
        mTabLayout.setupWithViewPager(shop_ViewPager);
    }

}
